package com.ylb.rent.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ylb.rent.config.PageConfig;
import com.ylb.rent.util.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;

import com.ruoyi.common.enums.BusinessType;
import  com.ylb.rent.entity.Security;
import com.ylb.rent.service.ISecurityService;

/**
 * 安全保障Controller
 * 
 * @author ylb
 * @date 2023-06-29
 */
@RestController
@RequestMapping("/security/security")
public class SecurityController
{
    @Autowired
    private ISecurityService securityService;

    /**
     * 查询安全保障列表
     */
    @PreAuthorize("@ss.hasPermi('security:security:list')")
    @GetMapping("/list")
    public String list(Security security , PageConfig pageConfig)
    {
        PageHelper.startPage(pageConfig);
        List<Security> list = securityService.selectSecurityList(security);
        return R.successJSONData(new PageInfo<>(list));

    }


    /**
     * 获取安全保障详细信息
     */
    @PreAuthorize("@ss.hasPermi('security:security:query')")
    @GetMapping(value = "/{id}")
    public String getInfo(@PathVariable("id") Long id)
    {
        return R.successJSONData(securityService.selectSecurityById(id));
    }

    /**
     * 新增安全保障
     */
    @PreAuthorize("@ss.hasPermi('security:security:add')")
    @Log(title = "安全保障", businessType = BusinessType.INSERT)
    @PostMapping
    public String add(@RequestBody Security security)
    {
        return R.successJSONData(securityService.insertSecurity(security));
    }

    /**
     * 修改安全保障
     */
    @PreAuthorize("@ss.hasPermi('security:security:edit')")
    @Log(title = "安全保障", businessType = BusinessType.UPDATE)
    @PutMapping
    public String edit(@RequestBody Security security)
    {
        return R.successJSONData(securityService.updateSecurity(security));
    }

    /**
     * 删除安全保障
     */
    @PreAuthorize("@ss.hasPermi('security:security:remove')")
    @Log(title = "安全保障", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public String remove(@PathVariable Long[] ids)
    {
        return R.successJSONData(securityService.deleteSecurityByIds(ids));
    }
}
